{% extends "admin/base.html" %}
{% block hscript %}
	<script type="text/javascript" src="themes/{{site.theme}}/style/jquery.min.js"></script>
    <script type="text/javascript" src="themes/{{site.theme}}/style/jquery.form.js"></script>
{% endblock %}
{% block nav %}
			<a href="?a=Roll">Link Roll</a>
			{%if link %}<a href="?a=Roll&d=create">Add new</a>{%endif%}
{% endblock %}
{% block content %}
<form action="?a=Roll" method="post" id="linkForm">
   <div class="wrap">
      <h2>{%if link %}Edit link{%else%}Add link{%endif%}</h2>
      <div id="poststuff">

<div id="submitlink" class="submitbox">

<div id="previewview">
</div>

<div class="inside">
<p>&nbsp;</p>
</div>

<p class="submit">
	<input type="submit" tabindex="6" value="Save" name="" class="button button-highlighted"/>&nbsp;
	<input type="checkbox" style="margin-left:10px;" tabindex="5" value="1" name="flag" class="button button-highlighted" {%if link.flag %}checked="checked"{%endif%}/>invisible
</p>

</div>

<div id="post-body">
<div class="stuffbox">
<h3>Title</h3>
<div class="inside">
	<input type="text" id="title" value="{{link.title}}" tabindex="1" size="30" name="title"/>
</div>
</div>

<div class="stuffbox">
<h3>Url</h3>
<div class="inside">
	<input type="text" id="url" value="{{link.url}}" tabindex="2" size="80" name="url" maxlength="230"/>
</div>
</div>
<div class="stuffbox">
<h3>Image</h3>
<div class="inside">
	<input type="text" id="image" value="{{link.image}}" size="80" name="image" tabindex="3" maxlength="230"/><br />
	{%if link.image %}<img alt="preview" src="{{link.image}}" />{% endif %}
</div>
</div>
<div class="stuffbox">
<h3>Description</h3>
<div class="inside">
	<textarea style="width: 675px;" cols="38" name="description" tabindex="4">{{link.description}}</textarea>
</div>
</div>

<input type="hidden" value="{{link.id}}" name="id"/>
<input type="hidden" value="{% if link %}update{% else %}add{% endif %}" name="d"/>

</div>
</div>

   </div>
</form>
{% endblock %}
{% block bscript %}    
<script type="text/javascript">
    $(document).ready(function() { 
    	var options = {
    	    	dataType: 'json',
    	    	success : function(data) {
	    				var hmd = $("#hiddenMessage");
	    				if (data.type == "error") {
	    					hmd.html("<div class='error'>" + data.message + "</div>");
	    				} else {
	    					hmd.html("<div class='info'>" + data.message + "</div>");
	    					{% if link|not %}
	    					$("#title").val('');
	    					$("#url").val('');
	    					$("#image").val('');
	    					{% endif %} 
	    				}
	    				hmd.show().focus();
    				},
    	};
    	$("#linkForm").ajaxForm(options);
    });
</script>
{% endblock %}